package org.example.im.client.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.example.im.bean.protocol.response.Send2UserResponsePacket;
import org.springframework.stereotype.Component;

/**
 * @author dingrui
 * @since 2022/2/11
 * @description 接收消息
 */
@Slf4j
@Component
public class Send2UserHandler extends SimpleChannelInboundHandler<Send2UserResponsePacket> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Send2UserResponsePacket send2UserResponsePacket) throws Exception {
        String fromUserId = send2UserResponsePacket.getFromUserId();
        String fromUserName = send2UserResponsePacket.getFromUserName();
        String msg = send2UserResponsePacket.getMessage();
        System.out.println("[C-Send2User] 接收到来自用户[userId={" + fromUserId + "} userName={" + fromUserName + "}]的消息={" + msg + "}");
    }
}
